﻿<%@ Page Culture="auto" UICulture="auto" Title="MForm modes" Language="C#" MasterPageFile="~/Site.Master"
    AutoEventWireup="true" CodeBehind="Modes.aspx.cs" Inherits="BM.Tools.WebControls.MForm.Example.Core.Modes" %>

<%@ Register Assembly="BM.Tools.WebControls.MForm" Namespace="BM.Tools.WebControls.MForm.Controls"
    TagPrefix="mf" %>
<%@ Register Assembly="BM.Tools.WebControls.MForm" Namespace="BM.Tools.WebControls.MForm.Controls.Additions"
    TagPrefix="mfadd" %>
<%@ Register Assembly="BM.Tools.WebControls.MForm" Namespace="BM.Tools.WebControls.MForm.Controls.ValueHandlers"
    TagPrefix="mfvh" %>
<%@ Register TagPrefix="mftitle" Namespace="BM.Tools.WebControls.MForm.Controls.Titles"
    Assembly="BM.Tools.WebControls.MForm" %>
<asp:Content ContentPlaceHolderID="Demonstration" runat="server">
    <p>
        In the following demonstration, the <code>Person</code> control is set to <code>View</code>
        mode. Hence, only the content of the <code>Reference</code> control can be modified.
    </p>
    <asp:XmlDataSource ID="XmlDataSource1" runat="server">
        <Data>
            <Team>
                <Reference>
                    <MainPerson>3</MainPerson>
                </Reference>
                <Person key="1">
                    <FirstName>Edgar</FirstName>
                    <Surname>Polgar</Surname>
                </Person>
                <Person key="2">
                    <FirstName>Francis</FirstName>
                    <Surname>Drake</Surname>
                </Person>
                <Person key="3">
                    <FirstName>Marty</FirstName>
                    <Surname>Kalish</Surname>
                </Person>
                <Person key="4">
                    <FirstName>Debra</FirstName>
                    <Surname>Glatz</Surname>
                </Person>
                <Person key="5">
                    <FirstName>Jeff</FirstName>
                    <Surname>Lazarus</Surname>
                </Person>                
            </Team>            
        </Data>
    </asp:XmlDataSource>
    <mf:RootValidator runat="server" ControlToValidate="Root1" />
    <mf:Root ID="Root1" DataSourceID="XmlDataSource1" runat="server">        
        <Contents>
            <mf:Branch Name="Team" runat="server">
                <Contents>
                    <mf:Branch Name="Reference" runat="server">
                        <Contents>
                            <mf:Leaf Name="MainPerson" runat="server" DataType="PositiveInteger" />
                        </Contents>
                    </mf:Branch>
                    <mf:Branch Name="Person" runat="server" Mode="View" MaxOccurs="100">
                        <Contents>
                            <mf:Leaf Name="key" runat="server" DataType="PositiveInteger" LeafType="Attribute">
                            </mf:Leaf>
                            <mf:Leaf Name="FirstName" runat="server">
                                <Additions>
                                    <mfadd:Restriction runat="server" RestrictionType="MaxLength" Value="40" />
                                </Additions>
                            </mf:Leaf>
                            <mf:Leaf Name="Surname" runat="server">
                                <Additions>
                                    <mfadd:Restriction runat="server" RestrictionType="MaxLength" Value="40" />
                                </Additions>
                            </mf:Leaf>
                        </Contents>
                    </mf:Branch>
                </Contents>
                <Additions>
                    <mfadd:IdentityConstraint runat="server" AutoFill="True" Name="PersonKey" Selector="Person/@key">
                        <mfadd:KeyRef Selector="Reference/MainPerson" />
                    </mfadd:IdentityConstraint>
                </Additions>
            </mf:Branch>
        </Contents>
        <UriMappings>
            <mf:UriMapping Prefix="xs" Namespace="http://www.w3.org/2001/XMLSchema" />
            <mf:UriMapping Prefix="" Namespace="" />
        </UriMappings>
    </mf:Root>
</asp:Content>
<asp:Content ID="Content1" ContentPlaceHolderID="Description" runat="server">
    <p>
        The MForm controls may be displayed in 2 modes:
    </p>
    <ul>
        <li><code>Edit</code> mode - the default mode, lets the user modify the content</li>
        <li><code>View</code> mode - lets the user only watch the contents</li>
    </ul>
    <p>
        In the <code>View</code> mode, the add and remove buttons are not rendered, and
        the leafs are always displayed as spans
    </p>
    <p>
        The mode can be set on any level of the MForm controls tree.
    </p>
    <p>
        The mode of each control is calculated in this way:
    </p>
    <ul>
        <li>If the control has the mode set, this mode is used</li>
        <li>If any of the controls precedessors has the mode set, the nearest precedessor's
            mode is used</li>
        <li>Otherwise the <code>Edit</code> mode is used</li>
    </ul>
</asp:Content>
